package com.litaomn.fang.hotload.ds;


import com.litaomn.fang.hotload.SO;
import com.tencent.mm.fang.FangBridge;
import com.tencent.mm.fang.FangHelpers;
import com.tencent.mm.fang.XC_MethodHook;

class FragmentHooker {
    private static class FragmentResumeHook extends XC_MethodHook {
        @Override
        protected void am(MethodHookParam param) throws Throwable {
            Object hasCalled = param.getObjectExtra("hasCalled");
            if (hasCalled != null) {
                return;
            }
            param.setObjectExtra("hasCalled", "true");
            ActivityHooker.sFragments.add(param.thisObject.getClass().getName());
        }
    }

    private static FragmentResumeHook fragmentResumeHook = new FragmentResumeHook();

    static void hookFragment() {
        Class<?> fragmentClass;
        try {
            fragmentClass = SO.master.loadClass("android.support.v4.app.Fragment");
        } catch (ClassNotFoundException e) {
            FangBridge.log("can not lod class \"android.support.v4.app.Fragment\"");
            FangBridge.log(e);
            return;
        }
        FangHelpers.fhm(fragmentClass, "onResume", fragmentResumeHook);
    }
}
